﻿@using OMR.Crawler.SampleMVC.Controllers

@model SolrNet.SolrQueryResults<OMR.Crawler.Core.CrawlDocument>

@{
    ViewBag.Title = "Search";
}

<h2>Search</h2>
@Html.Partial("_SearchBar", (string)@ViewBag.q) <!-- TODO: prevent xss -->
<br />
@*@foreach (var item in @Model.Stats.Keys)
{
    @item.Key <text>:</text> @item.Value <br />
}*@

<div style="width: 640px">
    @if (@Model.Count > 0)
    {
        <div style="color: #808080; text-align: right">
            Bulunan sonuç sayısı: @Model.NumFound, Arama süresi: <i>@((float)Model.Header.QTime/1000)sn</i>
        </div>
        <br />
    }

    <div>
        @if (@Model.SpellChecking != null && @Model.SpellChecking.Count > 0)
        {
            <text>Bunu mu demek istediniz:</text>
            foreach (var sc in @Model.SpellChecking)
            {
                foreach (var s in sc.Suggestions)
                {
            @Html.ActionLink(@s, "Search", new { q = @s })              
                }
            }<br />
        }
        @if (@Model.Count == 0)
        {
            <text><br />
            <i>Hiç kayıt bulunamadı...</i></text>
        }
        @foreach (var item in @Model)
        {
            <a href="@item.Location">@item.Title</a><i style="color: #808080;font-size:9pt"><text>[</text>@item.ContentType/@(item.Size / 8)<text>kb]</text></i><br />
            <div style="color: #051; font-size: 9pt">@item.Location</div>
            foreach (var h in @Model.Highlights[@item.Location])
            {
                var a = string.Join(", ", h.Value.ToArray());
            @Html.Raw(@a)
            }
            <br />
            <br />
        }
    </div>
</div>
<br />
@{
    string query = ViewBag.q;
}
@Html.Raw(@Html.Pager((int)@ViewBag.start, 10, @Model.NumFound, "Search?q=" + query))